#include"filestaunch.h"




                        /*         STRUCTURE TO KEEP INFORMATION ABOUT ENCRYPTED FILES         */
struct info
{
	int key_key;
	long int check;
	int tech;
	int pass;
}I;                    



/*		      DEFINITION OF THE FUNCTIONS		*/

/*				START 			        */

/*			ENCRYPTION TECHNIQUES		        */

int a[10],b[8];	
void encrypt( char *name, char *out_f ,int f)
{
	unsigned int iseed = (unsigned int)time(NULL);
    	srand (iseed);
	printf("\nINSIDE ENCRYPT");
	unsigned int s;
	int r;
	char kname[255],pas1[64],home[]="HOME/",*c_dir,*d_dir,cur_dir[255],c_d[255];//name[60];
	char FILESTAUNCH[]="HOME/FILESTAUNCH",*ptr,*ptr1,*ptr2,path[255];
	char fname[255],*e_dir;
	//strcpy(name,name1);
	FILE *fp,*EF;
	e_dir=(char *)get_current_dir_name();
	strcpy(cur_dir,e_dir);
	strcpy(c_d,e_dir);
	//fp=fopen(name,"r");
	DIR *dip,*dif;

	
	if((ptr=strstr(name,"/"))==NULL)
	{	
		(void)strcpy(kname,name);
		(void)strcpy(fname,name);
		
		printf("\nNAME %s %s %s",name,kname,fname);
		//cur_dir[0]=(char *)get_current_dir_name();
		(void)strcat(cur_dir,"/");
		(void)strcat(cur_dir,name);
		printf("\ncur dir %s",cur_dir);
		(void)strcpy(name,cur_dir);
		printf("\nNAME %s %s",name,kname);
	}
	else if((ptr1=strstr(name,"home"))==NULL)
	{
		(void)strcat(c_d,"/");
		(void)strcat(c_d,name);
		printf("\nhere cur dir %s",c_d);
		(void)strcpy(name,c_d);
		ptr2=strrchr(name,'/');
		(void)strcpy(fname,++ptr2);
		printf("\n fname %s",fname);
		(void)strcpy(kname,fname);
	}
		
	else
	{
		ptr=strrchr(name,'/');
		(void)strcpy(fname,++ptr);
		printf("\n fname %s",fname);
		(void)strcpy(kname,fname);
	}


	(void)strcat(kname,".key");
	
	struct dirent *dit;
	(void)strcpy(path,e_dir);
	(void)strcat(path,"/");
	if((ptr=strstr(out_f,"/"))==NULL)
	{
		
		(void)strcat(path,out_f);
		(void)strcpy(out_f,path);
	}
	else if((ptr=strstr(out_f,"home"))==NULL)
	{
		(void)strcat(path,out_f);
		(void)strcpy(out_f,path);
	}	
	dip=opendir(out_f);
	if(dip==NULL)
	{
		perror("\nWrong output directory sending output to HOME/FILESTAUNCH:");
		dif=opendir(home);
			perror("\nopendir");
		
		while ((dit = readdir(dif)) != NULL)
        	{
			if((strcmp(dit->d_name,"FILESTAUNCH"))!=0)
			{	
		
				if((mkdir(FILESTAUNCH,0777))!=0)
				{
					perror("mkdir");
					goto D;
				}
			}
		}
		D:
		if(closedir(dif)==-1)
		{
			perror("\nclose directory");
			return ;
		}
		
		(void)chdir(FILESTAUNCH);
		
	}
	else
	{
		printf("\nOutput directory found; \nSending output to %s",out_f);
		(void)chdir(out_f);
		printf("\nIn output directory %s",(char *)get_current_dir_name());
		
	}
	if(f==1)
	{
		printf("\nYou have chosen the fastest method");
		printf("\nEncryption starts now...");
		key_gen(name,fname);
		EF = fopen ( kname,"wb");
		I.pass=1;
		fwrite(&I,sizeof(I),1,EF);
		fclose(EF);
		(void)chdir(e_dir);
		printf("\nChanged to %s or %s directory",e_dir,(char *)get_current_dir_name());
		printf("\nEncryption  of the file %s is successfully done..\n",fname);
		return;
	}	
	printf("\n\n");
	char *pass=(char *)getpass("\nEnter password :");
	printf("\nYou entered '%s' as password",pass);

	printf("\nNAME%s",name);
	printf("\nEncryption starts now...");
	//printf("\ncheck sum NAME:%lu",checksum(name));
	//strcpy(kname,name);
	//strcat(kname,".key");
	//printf("\ncheck sum  NAME:%lu",checksum(name));

	s=rand();
	printf("\nrandom:%u",s);
	r=s%2;
	printf("\nr=%d",r);
	//int a=0;
	
	switch(r)
	{
		case 0:
		printf("\nINSIDE CASE 0");
		sub_cip(name,fname);
		key_gen(fname,fname);
		I.tech=0;
		//I.pass=0;
		pass_encrypt(fname,pass);
		EF = fopen ( kname,"wb");
		fwrite(&I,sizeof(I),1,EF);
		fclose(EF);
		printf("\n\tI-tech:%d",I.tech);
		printf("\n\tI_check:%lu",I.check);
		//printf("\n\tkey check sum:%lu",checksum(kname));
		printf("\nI.key_key:%d",I.key_key);
		printf("\nOUTSIDE CASE 0");
		break;
						
		case 1:
		printf("\nINSIDE CASE 1");
		key_gen(name,fname);
		sub_cip(fname,fname);
		I.tech=1;
		//I.pass=0;
		pass_encrypt(fname,pass);
		EF = fopen ( kname,"wb");
		fwrite(&I,sizeof(I),1,EF);
		fclose(EF);
		printf("\nI-tech5:%d",I.tech);
		printf("\nI_check:%lu",I.check);
		//printf("\nkey check sum:%lu",checksum(kname));
		printf("\nOUTSIDE CASE 1");
		break;

	}
	
	printf("\n%lu",I.check);
	printf("\n%d",I.tech);
	
		
	(void)chdir(e_dir);
	printf("\nChanged to %s or %s directory",e_dir,(char *)get_current_dir_name());
	printf("\nEncryption of the file %s is successfully done..\n",fname);
	
	
}

void pass_encrypt(const char *name,char *pass1)

{
	char temp[255]="temp";
	printf("\nINSIDE PASS_ENCRYPT");
	int i=0,sum=0,ch;
	char c;
	FILE *fp,*ft;
	//char temp[20]="temp";
	int n;
	printf("Password and name encrypt :%s\t%s\n",pass1,name);
	//printf("\nChecksum name:%lu",checksum(name));
	while(*(pass1+i)!='\0')
	{
		//printf("%d",*(pass1+i));
		sum=sum+*(pass1+i);
		i++;
	}
	printf("\nSum in pass_encrypt%d\n",sum);
	fp=fopen(name,"rb");
	ft=fopen(temp,"wb");
	while((ch=fgetc(fp))!=EOF)
	{	
		//printf("\n\t%c",ch);
		fputc(ch+sum,ft);
		//printf("\n\t%c",ch+sum);
	}
	
	fclose(fp);
	fclose(ft);
	//remove(name);
	rename(temp,name);
	I.pass=sum;
	I.check=checksum(name);
	//printf("\nChecksum name:%lu",checksum(name));
	printf("\nOUTSIDE PASS_ENCRYPT");
}
		

//ENCRYPTS USING SUBSTITUTION CIPHER

void sub_cip(char *name,char *fname)
{
	printf("\nINSIDE SUB_CIP");
	char arr1[] = {'1','2','u','i','o','p','[','-','=','\\','a','s','d',// THESE ARRAYS SUBSTITUION		
	       	       '!','@','#','$','%','^','&','*','(',')','_','+','|',  //ENCRYPTION AND DECRYPTION TECHNIQUE
	               'r','t','y',']','{','}','3','4','8','9','0','q','w','e',
	               'f','g','h','j','k','l',':',';','\"','\'','x','c','v',
	               'z','b','5','6','7','n','m',',','<','>','.','/','?','~'};

	char arr2[] = {'1','2','3','4','5','6','7','8','9','0','-','=','\\',
	               '!','@','#','$','%','^','&','*','(',')','_','+','|',
	               'q','w','e','r','t','y','u','i','o','p','[',']','{','}',
	               'a','s','d','f','g','h','j','k','l',':',';','\"','\'',
	               'z','x','c','v','b','n','m',',','<','>','.','/','?','~'};

	int i=0,ch;
	char temp[255]="temp";
	FILE *fs,*ft;
	printf("\nI-checksub1:%ld",I.check);
	//printf("\ncheck sum sub1:%lu",checksum(name));

	ft=fopen(temp,"wb");
	if(ft==NULL)
	{
		printf("\nUnable to open temporary file.");
		
	}
	fs=fopen(name,"rb");
	if(fs==NULL)
	{
		printf("\nNo such file or directory.");
		
	}
	while( (ch = fgetc(fs))!=EOF)
	{
		for(i=0;i<67;i++)			//SIMPLY EXCHANGES THE ELEMENTS BETWEEN THE ARRAYS array1 & array2
		{
			if(ch==arr1[i])
			{
				fputc(arr2[i],ft);
				break;
			}
		}
		if(i==67)
			fputc(ch,ft);
	}

	fclose(fs);
	fclose(ft);
	//remove(name);			//ACTUAL FILE IS REMOVED AND TEMP FILE IS RENAMED TO ACTUAL FILE
	rename(temp,fname);
	//I.sub_key=0;
	I.check=checksum(name);

	printf("\nI-checksub2:%ld",I.check);
	//printf("\ncheck sum sub2:%lu",checksum(fname));
	printf("\nI-techsub:%d",I.tech);
	//printf("\nI.sub_key :%d",I.sub_key);
	printf("\nOUTSIDE SUB_CIP");

}

//ENCRYPTION USING KEY GENERATOR

void key_gen( char *name, char *fname)
{
	char temp[200]="temp";
	printf("\nINSIDE KEY_GEN");
	unsigned int Key, i ,j=0;
	FILE *fp, *ft ;
	int ch;
	printf("\nI-checkkeygen1:%lu",I.check);
	//printf("\ncheck sum key1:%lu",checksum(name)); 
	unsigned int iseed = (unsigned int)time(NULL);
        srand (iseed);
	Key = rand();
	fun ( Key ) ;
	b [ 0 ] = a [ 5 ] ;
	b [ 1 ] = a [ 2 ] ;
	b [ 2 ] = a [ 9 ] ;
	b [ 3 ] = a [ 0 ] ;
	b [ 4 ] = a [ 4 ] ;
	b [ 5 ] = a [ 7 ] ;
	b [ 6 ] = a [ 3 ] ;
	b [ 7 ] = a [ 8 ] ;
	left ( ) ;
	left ( ) ;
	right( ) ;
	right( ) ;
	Key = Deci (  ) ;
	

	fp = fopen ( name, "rb" ) ;
	if ( fp == NULL )
	{
		printf("\nNo such file or directory.");
		return ;
	}
	ft = fopen ( temp, "wb" ) ;
	while ( ( ch = fgetc ( fp ) ) != EOF )
	{
		ch = ch ^ Key ;//THE KEY IS USED TO RAISE THE ASCII VALUE OF THE CHRACTER TO KEY TH POWER
		fputc ( ch, ft ) ;
	}
	fclose ( fp ) ;
	fclose ( ft ) ;
	//remove ( name ) ;
	rename ( temp, fname ) ;
	I.check=checksum(fname);
	I.key_key = Key ;//STORES KEY FOR FUTURE DECRYPTION
	printf("\nI-checkKgen2:%lu",I.check);
	//printf("\ncheck sum key2:%lu",checksum(fname));
	printf("\nI-techKgen:%d",I.tech);
	printf("\nI.key_key in key_gen:%d",I.key_key);
	printf("\nOUTSIDE KEY_GEN");
}

void  fun (unsigned int Key )//PRODUCES A BINARY STRING STORES IN a[]
{
	int i = 9 ;
	while ( Key > 0 )
	{
		a [ i-- ] = Key % 2 ;
		Key /= 2 ;
	}
}

void left ( void )//LEFT SHIFTS THE FIRST 4 BITS OF b[8]
{
	int i = 0, m ;
	for ( i = 0 ; i < 4 ; i ++ )
	{
		if ( i == 0 )
			m = b [ i ] ;
		else
			b [ i - 1 ] = b [ i ] ;
	}
	b [ 3 ] = m ;
}

void right ( void )//RIGHT SHIFTS THE LAST 4 BITS OF b[8]
{
	int i = 0, m ;
	for ( i = 4 ; i < 8 ; i ++ )
	{
		if ( i == 4 )
			m = b [ i ] ;
		else
			b [ i - 1 ] = b [ i ] ;
	}
	b [ 7 ] = m ;
}

unsigned int Deci(  )//PRODUCES A DECIMAL KEY
{
	int i ;
	unsigned int Key = 0 ;
	for ( i = 7 ; i >= 0  ; i -- )
		Key = Key + b [ i ] * pow ( 2, (7 - i) ) ;
	return Key ;
}




/*                            START				   */
/*			DECRYPTION TECHNIQUES			   */

void decrypt(char *name,char *kname)
{
	printf("\nINSIDE DECRYPT");
	int ch=0,key,check1;
	FILE *fs,*ft,*fp,*EF;
	struct info I;
	char fname[255],pas1[255];
	char *ptr,*e_dir,path[255];
	
	printf("\nDECRYPTION");


	e_dir=(char *)get_current_dir_name();
	(void)strcpy(path,e_dir);
	(void)strcat(path,"/");
	if((ptr=strstr(name,"/"))==NULL)
	{
		
		(void)strcat(path,name);
		(void)strcpy(name,path);
	}
	else if((ptr=strstr(name,"home"))==NULL)
	{
		(void)strcat(path,name);
		(void)strcpy(name,path);
	}
	/*R:	
	printf("\nEnter the name of the key file:");
	scanf("%s",kname);
	check1=check_name(kname);*/
	
	if(check1==-1)
		printf("\nInvalid key");;
	//e_dir=(char *)get_current_dir_name();
	
	(void)strcpy(path,e_dir);
	(void)strcat(path,"/");
	if((ptr=strstr(kname,"/"))==NULL)
	{
		
		(void)strcat(path,kname);
		(void)strcpy(kname,path);
	}
	else if((ptr=strstr(kname,"home"))==NULL)
	{
		(void)strcat(path,kname);
		(void)strcpy(kname,path);
	}
	
	EF = fopen ( kname,"rb");
	fread(&I,sizeof(I),1,EF);
	printf("\nI.pass %d",I.pass);
	if(I.pass==1)
	{
		printf("\nThe file was fast encrypted");
		dec_kg(name,I.key_key);
		fclose(EF);
		remove(kname);
		printf("\nThe file %s is decrypted successfully\n",name);
		return ;
	}
	
	//char *pass=(char *)getpass("\nEnter the password for the file: ");
	
	
	//printf("\nkey check sum%lu",checksum(kname));
	
		
	int a;
	char c;
	
	unsigned long int check;
	check=checksum(name);
	//printf("\ncheck sum dec:%lu",checksum(name));
	
	
	printf("\nI-check:%ld",I.check);
	printf("\nI-tech:%d",I.tech);
	if(check!=I.check)
	{
		printf("\nThere is some error please enter the details again");	
		return;
	}
	
	else if(check==I.check)
	{
		printf("\nDecryption begins now..");
		dec_pass(name,kname);
		switch(I.tech)
		{
			case 0:
			dec_kg(name,I.key_key);
			dec_sp(name);
			break;

			case 1:
			dec_sp(name);
			dec_kg(name,I.key_key);
			break;
	
		}
		
		fclose(EF);
		remove(kname);
		
		//printf("\nDEC-checksum:%lu",checksum(name));
	}
				
	else
	{
		fclose(EF);
		printf("\nThe encrypted file and its key dont match");
	}
	printf("\nOUTSIDE DECRYPT");
	printf("\nThe file %s is successfully decrypted\n",name);
		
}

void dec_pass(const char *name,char *kname)
{
	FILE *fp,*ft,*EF;
	printf("\nINSIDE DEC_PASS\n");
	int i=0,sum=0,ch;
	//char ch;
	char temp[200]="temp",*pass;
	pass=(char *)getpass("\nEnter the password for the file");
	printf("\nPassword and name decrypt :%s\t%s\n",pass,name);
	while(*(pass+i)!='\0')
	{
		//printf("%d",*(pass+i));
		sum=sum+*(pass+i);
		i++;
	}
	EF = fopen ( kname,"rb");
	fread(&I,sizeof(I),1,EF);
	if(sum!=I.pass)
	{
		printf("\nWrong password try again");
		return ;
	}
	fclose(EF);
	printf("\nSum in dec_pass%d\n",sum);
	fp=fopen(name,"rb");
	ft=fopen(temp,"wb");
	while((ch=fgetc(fp))!=EOF)
	{	
		fputc(ch-sum,ft);
	}
	
	fclose(fp);
	fclose(ft);
	remove(name);
	rename(temp,name);
	//printf("\nCheck sum dec_pass :name:%lu",checksum(name));
	printf("\nOUTSIDE PASS");
}


//DECRYPTION USING SUBSTITUION TECHNIQUE

void dec_sp( char *name)
{
	printf("\nINSIDE DEC_SP");
	FILE *ft,*fp ;
	char arr1[] = {'1','2','u','i','o','p','[','-','=','\\','a','s','d',// THESE ARRAYS SUBSTITUION		
       	       	       '!','@','#','$','%','^','&','*','(',')','_','+','|',  //ENCRYPTION AND DECRYPTION TECHNIQUE
                       'r','t','y',']','{','}','3','4','8','9','0','q','w','e',
                       'f','g','h','j','k','l',':',';','\"','\'','x','c','v',
                       'z','b','5','6','7','n','m',',','<','>','.','/','?','~'};

	char arr2[] = {'1','2','3','4','5','6','7','8','9','0','-','=','\\',
	               '!','@','#','$','%','^','&','*','(',')','_','+','|',
	               'q','w','e','r','t','y','u','i','o','p','[',']','{','}',
	               'a','s','d','f','g','h','j','k','l',':',';','\"','\'',
	               'z','x','c','v','b','n','m',',','<','>','.','/','?','~'};
	struct info I;
	int ch,i;
	char temp[200]="temp";
	printf("\nI.sub_key :%d",I.key_key);
	//printf("\ncheck sum sp1:%lu",checksum(name));
	fp = fopen(name,"rb");
	ft = fopen(temp,"wb");
	while( (ch = fgetc(fp))!=EOF)
	{
		for(i=0;i<67;i++)
		{
			if(ch==arr2[i])
			{
				fputc(arr1[i],ft);
				break;
			}
		}
		if(i==67)
			fputc(ch,ft);
	}
	fclose(fp);
	fclose(ft);
	remove(name);
	rename(temp,name);
	I.check=checksum(name);
	//printf("\ncheck sum sp2:%lu",checksum(name));
	printf("\nOUTSIDE DEC_SP");
}

//DECRYPTION USING KEY GENERATION TECHNIQUE

void dec_kg ( char *name, int Key )
{
	printf("\nINSIDE DEC_KG");
	FILE *fp, *ft ;
	int ch;
	char temp[200]="temp";
	//printf("\nI.key_key :%d",I.key_key);
	//printf("\ncheck sum key1:%lu",checksum(name));
	fp = fopen ( name, "rb" ) ;
	//if ( fp == NULL )
	//{
	//	printf ("\nCannot open Source file ");
	//	return ;
	//}
	ft = fopen ( temp, "wb" ) ;
	while ( ( ch = fgetc ( fp ) ) != EOF )
	{
		ch = ch ^ Key ;
		fputc ( ch, ft ) ;
	}
	fclose ( fp ) ;
	fclose ( ft ) ;
	remove ( name ) ;
	rename ( temp, name ) ;
	I.check=checksum(name);
	//printf("\ncheck sum key2:%lu",checksum(name));
	printf("\nOUTSIDE KEY_GEN");
}

void show_dir()
{

	DIR *dip;
	struct dirent *dit;
	int i=0;
	char name[255],str[255];
	char *str1;
	str1=(char *)get_current_dir_name();
	printf("\nYour current path is \t%s",str1);
	dip=opendir(str1);
	if(dip==NULL)
	{
		perror("open directory");
		return ;
	}
	printf("\n The list of files is below:\n");
	while ((dit = readdir(dip)) != NULL)
	{
	        i++;
	        printf("\n%s", dit->d_name);
	}
	printf("\nThere are total %d no of files in the folder",i); 
	if(closedir(dip)==-1)
	{
		perror("close directory");
		return ;
	}
	
		
}

int check_name(const char *name)
{
	FILE *fp;
	DIR *dip;
	
	char name1[255],*ptr,path[255],*path1;
	path1=(char *)get_current_dir_name();
	strcpy(path,path1);
	strcpy(name1,name);
	//printf("path is %s",path);
	if((ptr=strstr(name,"/home"))==NULL)
	{
		(void)strcat(path,"/");
		//printf("path is %s",path);
		(void)strcat(path,name);
		//printf("path is %s",path);
		(void)strcpy(name1,path);
	}
	dip=opendir(name1);	
	if(dip!=NULL)
	{
		printf("\nYou have specified a directory name...Please try entering  a valid file name");
		return -1;
	}
	fp=fopen(name1,"r");
	if(fp==NULL)
	{
		perror("\nFile not found..Try again");
		return -1;
	}
	return 1;
}

void show_file()
{
	char name[255];
	int ch;
	FILE *fp;
	printf("\n\nEnter the name of the file:\n");
	scanf("%s",name);
	fp=fopen(name,"rb");
	while((ch=fgetc(fp))!=EOF)
		printf("%c",ch);
}

unsigned long int checksum(const char *name)
{
	FILE *fp;
	unsigned long  int sum=0;
	int ch;
	fp=fopen(name,"rb");
	while((ch=getc(fp))!=EOF)
	sum+=ch;
	fclose(fp);
	return sum;
}


/*                       MAIN FUNCTION              */

int main(int argc, char *arv[])
{
	printf("\n******************Welcome to cryptography**********************");
	printf("\n\n");
    	int ch,i,p=-1,q=0,check,n,f=0,fp;
	char name[255],out_f[255],ip[40][255],key[255];
	n=argc;
	for(i=0;i<n;i++)
		strcpy(ip[i],arv[i]);
	if(n<2)
	{
				
		while(ch!=0)
		{
			printf("\n\nEnter your choice :\n\t 1.encrypt,\n\t 2.Fast encrypt\n\t 3.decrypt,");
			printf("\n\t 4.show folder,\n\t 5.show file  \n\t 0.Exit\n");
			scanf("%d",&ch);
			switch(ch)
			{
				case 1:
				printf("\n");
				printf("\nCurrent directory is:%s",(char *)get_current_dir_name());
				printf("\nEnter the name :");
				scanf("%s",name);
				check=check_name(name);
				if(check==-1)
					break;
				else
				{
					printf("\nEnter output folder name;Default is HOME/FILESTAUNCH :");
					scanf("%s",out_f);
					//check=check_name(out_f);
					//if(check==-1)
					//	printf("\nGoing for default directory");
					encrypt(name,out_f,0);
					break;
				}
				
				case 2:
				printf("\n");
				printf("\nEnter the name :");
				scanf("%s",name);
				check=check_name(name);
				if(check==-1)
					break;
				else
				{
					printf("\nEnter output folder name;Default is HOME/FILESTAUNCH :");
					scanf("%s",out_f);
					//check=check_name(out_f);
					//if(check==-1)
					//	printf("\nGoing for default directory");
					encrypt(name,out_f,1);
					break;
				}
				case 3:
				printf("\n");
				printf("\nEnter the name of the file to be decrypted:");
				scanf("%s",name);
				check=check_name(name);
				if(check==-1)
					break;
				printf("\nEnter the name of the file to be decrypted:");
				scanf("%s",key);
				check=check_name(key);
				if(check==-1)
					break;
				decrypt(name,key);
				break;

				case 4:
				printf("\n");
				show_dir();
				break;

				case 5:
				printf("\n");
				show_file();
				break;

				

				case 0:
				printf("\nThank you for using this software\n");
				return;

				default:
				printf("\n\nWrong Input!!!!!TRY AGAIN\n\n");
				printf("\nThank you for using this software\n");
				return;
			}
		}

	}
	
	else
	{
		
		for(i=1;i<n;i++)
		{
			if((strcmp(ip[i],"-d"))==0)
			{	
				q=1;
				break;
			}
			
		}
		for(i=1;i<n;i++)
		{
			if((strcmp(ip[i],"-f"))==0)
			{	
				f=1;
				fp=i;
				break;
			}
			
		}
		if(q==1)
		{
			
			(void)strcpy(name,ip[2]);
			(void)strcpy(key,ip[3]);
			printf("\n Going to check :%s",name);
			check=check_name(name);
			if(check==-1)
			{
				printf("\nSorry decryption was not successful Wrong name\n");
				return;
			}
			printf("\n Going to check :%s",key);
			check=check_name(key);
			if(check==-1)
			{
				printf("\nSorry decryption was not successful Wrong key\n");
				return;
			}
			decrypt(name,key);
			return 0;
		}
		
		for(i=1;i<n;i++)
		{
			if((strcmp(ip[i],"-o"))==0)
			{
				p=i;
				(void)strcpy(out_f,ip[i+1]);
				break;
			}
			
		}
		if(p==-1)
		{
			printf("\nEnter the output folder name; Default is HOME/FILESTAUNCH : ");
			scanf("%s",out_f);
			//check=check_name(out_f);
			//	if(check==-1)
			//		printf("\nGoing for default directory");
		}

		for(i=1;i<n;i++)
		{
			if(i==p)
				continue;
			else if(i==p+1)
				continue;
			else if(i==fp)
				continue;
			else
			{
				printf("\n Going to check :%s",ip[i]);
				check=check_name(ip[i]);
				if(check==-1)
					continue;
				else
					encrypt(ip[i],out_f,f);
			}
		}
	}		

	printf("\nThank you for using this software\n");
	return 0;
}

